﻿using UnityEngine;
using System.Collections.Generic;

public class LoadedAssetBundle {

	private int refCount;

	#if UNITY_EDITOR
	public List<string> refList = new List<string> ();
	#endif

	private AssetBundle assetBundle;

	public AssetBundle AssetBundle
	{
		get
		{
			return this.assetBundle;
		}
	}

	private Object mainAsset;

	public Object MainAsset {
		get
		{
			return this.mainAsset;
		}
	}

	private Object[] allAsset;

	public Object[] AllAsset {
		get
		{
			return this.allAsset;
		}
	}

	//UI_Atlas随意加载一个sprite即可，整个texture2d都会加载进来
	public string AssetType {
		get
		{
			return "UI";
		}
	}

	private string name;

	public string Name {
		get
		{
			return this.name;
		}
	}

	public LoadedAssetBundle(AssetBundle assetBundle, string name, Object[] allAsset, Object mainAsset){
		this.assetBundle = assetBundle;
		this.name = name;
		this.allAsset = allAsset;
		this.mainAsset = mainAsset;
	}

	public void Release(){
		refCount--;
		if (refCount == 0) {
			refList.Clear ();
			assetBundle.Unload (true);
			assetBundle = null;
		}
	}

	public void Retain(){
		refCount++;
	}

	public int GetRefCount(){
		return this.refCount;
	}

}
